Thanks for your help. I have modified this as much as possible, and some of the questions I have been able to answer but I would appreciate any corrections you might fine. Also, some of the answers have been bunched up to save space on pages to make things more ledgible hopefully. I need some help with getting these done in time so I can use this info to study for an upcoming exam. Feel free to complete this in a .docx format and highlight or just only place the answers after the questions. I'm open to either, I will modify as I need from there.. just want to make sure I am studying with the right info. Thanks! 1: What two categories of variables can classes define? Instance and class variables 2: Which is the correct syntax for a mutator method? public void setWeight(double weight) { this.weight = weight; } 3: Which statement shows the correct way to declare and initialize a named constant that represents absolute zero? final double absoluteZero = -273.15; 4: In the following class: public class Height { private double height; private String unitsOfMeasurement; //************************ public Height() { this.unitsOfMeasurement = "in"; } public void setHeight(double height) { this.height = height; this.unitsOfMeasurement = "cm"; } public void setHeight(double height, String unitsOfMeasurement) { this.height = height; this.unitsOfMeasurement = unitsOfMeasurement; } public void print() { System.out.println(this.height + " " + this.unitsOfMeasurement); } } // end class Height Which method is the constructor? Answer: The Height method 5:Java primitive types include _________. long, double, character, float, integer and boolean 6: What is the name for the circled items in the following statement? modulus specifier precision specifier format specifier flags specifier 7: Which Java operator is used for concatenation? + 8: Given the following code fragment (presume there is a class called Car implemented): Car mazdaCar = new Car(); Car subaruCar = new Car(); mazdaCar.setYear(2008); mazdaCar.setColor(“black”); subaruCar = mazdaCar; subaruCar.setYear(2011); mazdaCar.printYear(); What will display on the screen for mazdaCar’s year when mazdaCar executes printYear()? 2008 9: Given the following method from a class: public double calculateArea(double length, double width) { double area; area = length * width; return area; } … What is the scope of the variables length and width? None of the above. Global to all objects created from the class. Local to the method. Global to the class. 10: In the following code fragment: 5 Person person1 = new Person(); 6 Person person2 = new Person(); 7 8 person1.setName("Bugs Bunny"); 9 person2.setName("Daffy Duck"); 10 System.out.println(person1.getName() + ", " + person2.getName()); 11 12 person1.swapPerson(person2); 13 System.out.println(person1.getName() + ", " + person2.getName()); … What is being passed to the swapPerson method in line 12: a class reference an object an object reference a class 11. In the following Java code fragment: … int postion1 = 15; int postion2 = 18; int distanceApart = Math.abs(position1 - position2); … What type of method is the Math.abs() method? Class method 12. When public method needs to access both class members (variables and methods) and instance members (variables and methods), the method must be a / an _________ method. instance None of the above. class helper 13. In the following class: public class Height { private double height; private String unitsOfMeasurement; public Height() { this.unitsOfMeasurement = "in"; } public void setHeight(double height) { this.height = height; this.unitsOfMeasurement = "cm"; } public void setHeight(double height, String unitsOfMeasurement) { this.height = height; this.unitsOfMeasurement = unitsOfMeasurement; } public void print() { System.out.println(this.height + " " + this.unitsOfMeasurement); } } // end class Height Which method is overloaded? The print method The setHeight method The Height method None of the methods are overloaded. 14. What must a method return if the method implements method call chaining? A class variable Null The calling object The class 15. Which code segment is representative of a properly formatted nested loop? a.) while(i<5) { while(j<3) { … }do; } b.) do { while(j<3) { … } }while(i<5) c.) while(i<5) {1 … } while(j<3) { … } d.) do { while(j<3) { … } }while(i<5); 16. What is the fundamental difference between a do loop and a while loop? Code inside a do loop will never be executed. Code inside a while loop is guaranteed to execute at least once. Do loops and while loops are the same. Code inside a do loop is guaranteed to execute at least once. 17. What is the meaning of the java statement: import java.util.Scanner;? It tells the java compiler to include the Scanner class from the utility package. It tells the java compiler to exclude only the Scanner class from the compile process. It signals the java compiler to scan the source code for errors. None of the above. 18. Given the following code fragment: … double interestRate = 0.05; double balance = 100.5; int interestInDollars = (int)(interestRate * balance); System.out.println(interestInDollars); … What value will display on the screen? 5.025 0 5 5.03 19. What is the significance of using the access modifier “private” with instance variables? It makes the variables inaccessible from within the object. Using “private” provides data encapsulation. It makes instance variables easier to access from outside the object. The “private” access modifier should never be used. 20. Given the following code fragment: … System.out.println("\"Four score and seven years ago…\""); … What will display on the screen? \Four score and seven years ago…\ “Four score and seven years ago…” "\"Four score and seven years ago…\"" Four score and seven years ago… 21. Given the following, which is the correct file name and extension to use when saving the file? public class SomeJavaClass { public static void main(String[] args) { System.out.print(“Java is ?”); }//end main }//end someJavaClass SomeJavaClass.java someJavaClass.java SomeJavaClass.txt someJavaClass.txt 22. In the context of OOP, objects __________. persist forever after being instantiated have state and behavior contain only accessor methods do not encapsulate data 23. Given the following code fragment. (presume there is a Hat class with a constructor that requires the hat type, price and color as arguments and there is a accessor method called getPrice that returns the price): … Hat hat1 = new Hat(“baseball”, 5.21, “blue”); int quantityToOrder = 0; double totalPrice = 0.0; Scanner userInput = new Scanner(System.in); System.out.print(“How many hats to order? “); quantityToOrder = Integer.parseInt(userInput.nextLine()); totalPrice = (hat1.getPrice() * quantityToOrder); System.out.println(“Order Total = $“ + totalPrice); … What will display on the screen when the user orders 4 hats? Order Total = $5 Order Total = $5.21 Order Total = $20 Order Total = $20.84 25. In the following Java code fragment: public class SomeClass { private static int someVariable; … }//end SomeClass What is the significance of the keyword static? It makes the variable someVariable a class variable None of the above It makes the variable someVariable a local method variable It makes the variable someVariable an instance variable 25. Given the following code fragment: … String name = "Joseph Cool"; System.out.println(name.charAt(5)); … What will display on the screen? e h 5 p 26. Instance methods ___________. specify the object attributes (data) specify the object behaviors must contain the static keyword in their definition can be used without creating an object 27. Given the following code fragment: … int operand1 = 4; int operand2 = 3; double result = operand1 / operand2; System.out.println(result); … What is displayed on the screen? 1 0 1.3333333333333333 1.0 28. Given the following code fragment: … boolean logicValueA = true; boolean logicValueB = true; System.out.println("Boolean Result: " + (logicValueA && logicValueB)); … What will display on the screen? Boolean Result: false Boolean Result: true Boolean Result: and Boolean Result: or 29. A class specifically written to use other classes in its main method is called a _________. driven class static class main class driver class 30. Given the following code fragment: … boolean logicValueA = true; boolean logicValueB = false; System.out.println("Boolean Result: " + (!logicValueA || logicValueB)); … What will display on the screen? a.) Boolean Result: true b.) Boolean Result: false c.) Boolean Result: and d.) Boolean Result: or 31. What is the term for the lower and upper case pattern that must be used for variable and method identifiers? camel case straight case None of the above. alternating case 32. Given the following code fragment: … int x = 5; int y = 8; int z = 0; while(y < 20) { z = x + y; x = y; y = z; System.out.println(y); } if(y > 22) { System.out.println(z); } else if(y < 22) { System.out.println(x); } … What will display on the screen? a.) 13 25 13 b.) 13 21 21 c.) 13 28 28 d.) 13 21 13 33. Which statement shows the correct way to define a method that does not provide a return value? a.) public void displayFraction(int numerator, int denominator) { … } b.) public int displayFraction(int numerator, int denominator) { … } c.) public null displayFraction(int numerator, int denominator) { … } d.) public Fraction displayFraction(int numerator, int denominator) { … } 34. The following code generates a compiler error. Which line is causing the error and what is wrong with it? 1 public class Book 2 { 3 private String author; 4 private int numberOfPages; 5 private String title; 6 7 //******************* 8 9 public Book(String author, int numberOfPages, String title) 10 { 11 this.author = author; 12 this.numberOfPages = numberOfPages; 13 this.title = title; 14 } 15 16 public String getAuthor() 17 { 18 return this.author; 19 } 20 }//end Book class 21 22 public class BookDriver 23 { 24 public static void main(String[] args) 25 { 26 String bookTitle = "The Relic"; 27 String bookAuthor = "Douglas Preston"; 28 int bookTotalPages = 439; 29 Book myBook = new Book(); 30 31 System.out.println(myBook.getAuthor()); 32 }//end main 33 }//end BookDriver Your Answer: 35. The following code generates a compiler error. Which line is causing the error and what is wrong with it? 1 public class TestClass 2 { 3 public static void main(String[] args) 4 { 5 String testString = "Java"; 6 for(int i; i < testString.length(); i++) 7 { 8 System.out.println(i); 9 } 10 }//end main 11 }//end TestClass Your Answer: 36. The following code generates a compiler error. Which line is causing the error and what is wrong with it? 1 import java.util.Scanner; 2 3 public class TestClass 4 { 5 public static void main(String[] args) 6 { 7 Scanner userInput = new Scanner(System.in); 8 String inputName; 9 10 System.out.print("Enter your name: "); 11 Inputname = userInput.nextLine(); 12 13 System.out.println("Hello " + inputName + "!"); 14 }//end main 15 }//end TestClass Your Answer: Line 11 - Should be inputName 37. The following code generates compiler errors. Which line is causing the error and what is wrong with it? 1 public class TestClass 2 { 3 public static void main(String[] args) 4 { 5 char characterToPrint = '*'; 6 for(int i = 1; i < 5; i++) 7 { 8 System.out.println(characterToPrint); 9 } 10 System.out.println(i + " stars"); 11 }//end main 12 }//end TestClass Your Answer: Line 10 - Variable i is not declared outside of loop 38. Write the Hello World program, be precise, include comments, prologue, etc. if needed. (4 points) Your Answer: //////////////////////////////////////////////////////////////////////////////// * Hello World program * This program displays the words Hello World //////////////////////////////////////////////////////////////////////////////// public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); //Print out statement } }//End hello 39. Write the source code for a class called Temperature that does the following: (5 points) a. Prompts the user to input a temperature b. Prints “Too Hot!” when the input temperature is above 75 c. Prints “Too Cold!” when the input temperature is below 40 d. Prints “Just Right!” when the input temperature is 40 to 75 e. Be precise, include comments, prologue, etc. if needed. Your Answer: import java.util.Scanner; public class Temperature { public static void main(String[] args) { double temp; Scanner scan=new Scanner(System.in); System.out.println("enter temperature :"); temp=scan.nextDouble(); if(temp>75) { System.out.println("Too Hot!"); } else if(temp<40) { System.out.println("Too Cold!"); } else if(temp<75&&temp>40) { System.out.println("Just Right!"); } } } 40. Write a java code segment that will count all uppercase letters in a previously defined String s. You are not required to write a whole program, only a code segment int count = 0; for(int i = 0; i < myString.length(); i++){ if(isUpperCase(myString.charAt(i))) count++; } System.out.println(count);